<?php
    session_start();

    function __autoload($className) {
            $basePath = dirname(__FILE__);

            if(file_exists($basePath."/../Class/$className.php"))
                    require_once($basePath."/../Class/$className.php");
            else if(file_exists($basePath."/../Sql/$className.php"))
                    require_once($basePath."/../Sql/$className.php");
            else if(file_exists($basePath."/../Php/$className.php"))
                    require_once($basePath."/../Php/$className.php");
            else if(file_exists($basePath."/../Exception/$className.php"))
                    require_once($basePath."/../Exception/$className.php");


    }

    function exception_handler(Exception $Ex) {
            new ExceptionHandler($Ex);
    }
    
    set_exception_handler('exception_handler');

    function exception_error_handler($errno, $errstr, $errfile, $errline) {
            $throw = false;
            switch($errno) {
                case E_NOTICE: case E_USER_NOTICE:
                            $errors = "Notice";
                            return false;
                            break;
                case E_WARNING: case E_USER_WARNING:
                            $errors = "Warning";
                            return false;
                            break;
                case E_ERROR: case E_USER_ERROR:
                            $errors = "Error";
                            return false;
                            break;
            }

            throw new CustomException("{$errors} - {$errstr}" , 0, $errno, $errfile, $errline);
            $report = false;
            $report = ($errors == "Notice" && DEBUG_REPORT_NOTICE) || ($errors == "Warning" && DEBUG_REPORT_WARNING);
            if($report) {
                    echo "<pre>";
                    echo "{$errors} - {$errstr}' on {$errfile} line {$errline}";
                    echo "</pre>";
            }
    }

    set_error_handler("exception_error_handler");

    header("Content-type: text/html; charset=utf-8");


    if( !isset( $_SESSION['USR_PRIVILEGIO'] ) ) {
        header( "location: ../Index.php?error=2" );
    }
    
?>